package com.market.pay.details;

import com.market.entity.dto.OrderDto;
import com.market.pay.base.PricingStrategy;
import com.market.util.CommonConstants;

import java.math.BigDecimal;

// 满减策略（满100减10）
public class FullReductionStrategy implements PricingStrategy {
    private final PricingStrategy baseStrategy;

    public FullReductionStrategy(PricingStrategy baseStrategy) {
        this.baseStrategy = baseStrategy;
    }

    @Override
    public BigDecimal calculateTotal(OrderDto orderDto) {
        BigDecimal total = baseStrategy.calculateTotal(orderDto);
        if (total.compareTo(CommonConstants.ONE_HUNDRED)>= 0) {
            total = total.subtract(CommonConstants.ONE_HUNDRED_DISCOUNT_AMOUNT);
        }
        return total;
    }
}

